<?php
/** 
 *  Edit page content
 *
 * @author     Mario Schillermann <info@rockit-flash.com>
 * @encoding   UTF-8 äöüßÖÄÜ
 * @copyright  © 2011 Mario Schillermann (info@rockit-flash.com)
 * @license    GNU GPL v2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
 * @uses       
 * @package    Minipage
 * @subpackage Model
 * @todo
 */
class Minipage_Model_Page
{
    /**
     * Save new page content
     *
     * @param array $request
     * @return boolean
     */
    static function save($request)
    {
        $file = APPLICATION_PATH . '/../home/default/minipage/index.';

        if(!is_writable(realpath($file . 'ini')) || !is_writable(realpath($file . 'phtml'))) {
            throw new Exception('Files are not writable!');
        }

        $config = new Zend_Config(array(), true);
        $config->head = array();
        $config->head->title = $request["title"];
        $config->head->meta = array();
        $config->head->meta->keywords = $request["keywords"];
        $config->head->meta->description = $request["description"];
        $config->head->meta->author = $request["author"];
        /** Stores header datas */
        $writer =  new Zend_Config_Writer_Ini(
            array(
                'config'   => $config,
                'filename' => $file . 'ini'));
        $writer->write();

        /** Stores body content datas */
        $handle = fopen(realpath($file . 'phtml'),"w");
        fwrite($handle, $request["content"]);
        fclose($handle);
    }
}